#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

int ind[N], tim;
int c[N], fa[N], dfn[N], R[N], eid[N], n, dep[N];
vector < tuple < int, int, int > > G[N];

void dfs(int x, int p) {
	fa[x] = p; dep[x] = dep[p] + 1; ind[dfn[x] = R[x] = ++tim] = x;
	for(auto v : G[x]) {
		int y, w, i; tie(y, w, i) = v; if(y == p) continue;
		eid[i] = y; c[y] = c[x] ^ w; dfs(y, x); ind[R[x] = ++tim] = x;
	}
}

const int inf = 3e8;

struct node {
	int mxl[2], mxr[2], mn[2], mx[2], res;
	node() {
		mxl[0] = mxl[1] = mxr[0] = mxr[1] = mx[0] = mx[1] = res = -inf;
		mn[0] = mn[1] = inf;
	}
} val[2][N << 2];

void init(node &val, int c, int d) { val = node(); val.mn[c] = val.mx[c] = d; val.mxl[c] = val.mxr[c] = -d; }

void init(int o, int x) { init(val[0][o], c[x], dep[x]); init(val[1][o], c[x] ^ 1, dep[x]); }

node operator + (node a, node b) {
	node c; c.res = max(a.res, b.res);
	rep(i, 0, 1) {
		c.mxl[i] = max(a.mxl[i], b.mxl[i]), c.mxr[i] = max(a.mxr[i], b.mxr[i]), c.mn[i] = min(a.mn[i], b.mn[i]), c.mx[i] = max(a.mx[i], b.mx[i]);
		chkmax(c.mxl[i], max(a.mx[i] - b.mn[i] * 2, a.mx[i] - b.mn[i ^ 1] * 2));
		chkmax(c.mxr[i], max(b.mx[i] - a.mn[i] * 2, b.mx[i] - a.mn[i ^ 1] * 2));
		chkmax(c.res, a.mxl[i] + b.mx[i]); chkmax(c.res, b.mxr[i] + a.mx[i]);
	} return c;
}

bool rev[N << 2];

void pt(int o) { rev[o] ^= 1, swap(val[0][o], val[1][o]); }
void pd(int o) { if(rev[o]) pt(o << 1), pt(o << 1 | 1), rev[o] = 0; }
void pu(int o) { val[0][o] = val[0][o << 1] + val[0][o << 1 | 1]; val[1][o] = val[1][o << 1] + val[1][o << 1 | 1]; }

void build(int o = 1, int l = 1, int r = tim) {
	if(l == r) return init(o, ind[l]), void(); int mid = l + r >> 1;
	build(o << 1, l, mid); build(o << 1 | 1, mid + 1, r); pu(o);
}

void upd(int xl, int xr, int o = 1, int l = 1, int r = tim) {
	if(xl == l && xr == r) return pt(o); int mid = l + r >> 1; pd(o);
	if(xr <= mid) upd(xl, xr, o << 1, l, mid); else if(xl > mid) upd(xl, xr, o << 1 | 1, mid + 1, r);
	else upd(xl, mid, o << 1, l, mid), upd(mid + 1, xr, o << 1 | 1, mid + 1, r); pu(o);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 1, n - 1) { int u = in, v = in, w = in; G[u].eb(v, w, i); G[v].eb(u, w, i); }
	dfs(1, 0); build(); int Q = in; //cerr << val[0][1].res << endl;
	//	rep(i, 1, tim) cerr << ind[i] << " " ;
	//cerr << endl;
	while(Q--) {
		int x = in; x = eid[x]; upd(dfn[x], R[x]);
		printf("%d\n", max(val[0][1].res, val[0][1].mx[0] - 1));
	}   
	return 0;
}
